package com.cy.pj.sys.controller;

import com.cy.pj.common.pojo.JsonResult;
import com.cy.pj.sys.pojo.SysMenu;
import com.cy.pj.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/menu/doFindObjects")
    @ResponseBody
    public JsonResult doFindObjects(){
        return new JsonResult(sysMenuService.findObjects());
    }

    @PostMapping("/menu/doSaveObject")
    @ResponseBody
    public JsonResult doSaveObject(SysMenu entity){
        sysMenuService.saveObject(entity);
        return new JsonResult("save ok");
    }

    @PostMapping("/menu/doUpdateObject")
    @ResponseBody
    public JsonResult doUpdateObject(SysMenu entity){
        sysMenuService.UpdateObject(entity);
        return new JsonResult("update ok");
    }

    @PostMapping("/menu/doDeleteObject")
    @ResponseBody
    public JsonResult doDeleteObject(@PathVariable Integer id){
        return new JsonResult(sysMenuService.deleteObject(id));
    }

    @CrossOrigin
    @GetMapping("/menu/doFindZtreeMenuNodes")
    @ResponseBody
    public JsonResult dofindZtreeMenuNodes(){
        return new JsonResult(sysMenuService.findZtreeMenuNodes());
    }
}
